import java.text.SimpleDateFormat;
import java.util.Calendar;

//An instance of the Trip class is just a collection of two dates.
public class Trip {
	
	
	
	//Data members
	private Calendar firstDate;
	private Calendar secondDate;
	private int id;
	public final static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy");
	private int vacantSingleCabins;
	private int vacantFamilyCabins;
	
	public Trip(Calendar startDate, Calendar endDate, int tripID, int numSingleCabins, int numFamilyCabins) throws ManagementException{
		
		if (startDate.compareTo(endDate) < 0){ // must return less than 0
			firstDate = startDate;
			secondDate = endDate;
			id = tripID;
		
		}
		else { //Bad date arrangement. End date must be after to begin date. 
			
			throw new ManagementException("You tried to assign a start date that is after the end date to a cruise");
			
		}
	}
	
	public Calendar getStart(){
		
		return firstDate;
		
	}
	
	public Calendar getEnd(){
		
		return secondDate;
	}
	
	//CabinType
	// 	1 = Single
	//  2 = Family
	public boolean reserveCabin(int cabinType){
		
		//Single Cabin Logic. Does vacancy exist? If so decrement vacancies and return true. Else return false. 
		if (cabinType == 1){
			if (vacantSingleCabins != 0){
				vacantSingleCabins--;
				return true;
			}
			
		}
		
		//Family Cabin Logic. Does vacancy exist? If so decrement vacancies and return true. Else return false. 
		else if (cabinType == 2){
			if (vacantFamilyCabins != 0){
				vacantFamilyCabins--;
				return true;
			}
			
			
		}
		
		//If we got to this line, then no cabins are vacant... Or we got a value for cabinType that is not respected.
		return false;
	}
	
	public String toString(){
		
				
		return id + ": " + 
				simpleDateFormat.format(firstDate.getTime())
				+ " - " +
				simpleDateFormat.format(secondDate.getTime());
		
		
	}
	


}

